package com.company.card_service.api;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.company.card_service.model.*;
import com.company.card_service.serviceImpl.*;
import com.company.card_service.vo.Result;
import com.company.card_service.vo.ResultCodeEnum;
import com.company.card_service.vo.UEmployeeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

/**
 * <p>
 *  前端小程序页面控制器
 * </p>
 *
 * @author 赵志浩
 * @since 2022-09-15 04:15:06
 */
@Api("小程序端员工信息")
@RestController
@Slf4j
@RequestMapping("api/company/employee")
public class ApiEmployeeController {

    @Autowired
    EmployeeServiceImpl employeeService;

    @Autowired
    AddPhoneServiceImpl addPhoneService;

    @Autowired
    ForwardViewServiceImpl forwardViewService;

    @Autowired
    EmployeeDownloadServiceImpl employeeDownloadService;

    @Autowired
    EmployeeViewServiceImpl employeeViewService;

    @Autowired
    MessageServiceImpl messageService;

    @Autowired
    EmployeeProfilesServiceImpl employeeProfilesService;

    @GetMapping("getEmployee/{id}")
    @ApiOperation("小程序显示员工所有信息")
    public Result getEmployee(@PathVariable Long id) {
        UEmployeeVo allDataOfEmployee = employeeService.getAllDataOfEmployee(id);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(), allDataOfEmployee);
    }

    @PostMapping("addTel")
    @ApiOperation("添加添加通讯录的数据")
    public Result addTel(@RequestBody AddPhone addPhone) {
        addPhoneService.saveAll(addPhone);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @PostMapping("addForward")
    @ApiOperation("添加转发的数据")
    public Result addForward(@RequestBody ForwardView forwardView) {
        forwardViewService.saveAll(forwardView);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @PostMapping("downloadEmployee")
    @ApiOperation("添加下载的数据")
    public Result downloadEmployee(@RequestBody EmployeeDownload employeeDownload) {
        employeeDownloadService.saveAll(employeeDownload);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage());
    }

    @GetMapping("getDownloadEmployee/{employeeId}")
    @ApiOperation("获取下载的数据")
    public Result getDownloadEmployee(@PathVariable Long employeeId) {
        LambdaQueryWrapper<EmployeeDownload> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EmployeeDownload::getEmployeeId, employeeId)
                .lt(EmployeeDownload::getCreateTime,new Date());
        long count = employeeDownloadService.count(lambdaQueryWrapper);
        return Result.success(count);
    }

    @GetMapping("getForward/{employeeId}")
    @ApiOperation("获取转发的数据")
    public Result getForward(@PathVariable Long employeeId) {
        LambdaQueryWrapper<ForwardView> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ForwardView::getEmployeeId, employeeId)
                .lt(ForwardView::getCreateTime,new Date());;
        long count = forwardViewService.count(lambdaQueryWrapper);
        return Result.success(count);
    }

    @GetMapping("getUserView/{employeeId}")
    @ApiOperation("获取访客的数据")
    public Result getUserView(@PathVariable Long employeeId) {
        LambdaQueryWrapper<EmployeeView> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(EmployeeView::getEmployeeId, employeeId)
                .lt(EmployeeView::getCreateTime,new Date());
        long count = employeeViewService.count(lambdaQueryWrapper);
        return Result.success(count);
    }

    @GetMapping("getMessageView/{employeeId}")
    @ApiOperation("获取留言的数据")
    public Result getMessageView(@PathVariable Long employeeId) {
        LambdaQueryWrapper<Message> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Message::getEmployeeId, employeeId)
                .lt(Message::getCreateTime,new Date());
        long count = messageService.count(lambdaQueryWrapper);
        return Result.success(count);
    }

    @GetMapping("getTelView/{employeeId}")
    @ApiOperation("获取通讯录的数据")
    public Result getTelView(@PathVariable Long employeeId) {
        LambdaQueryWrapper<AddPhone> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(AddPhone::getEmployeeId, employeeId)
                .lt(AddPhone::getCreateTime,new Date());
        long count = addPhoneService.count(lambdaQueryWrapper);
        return Result.success(count);
    }

    @PostMapping("/addEmployeeProfile")
    @ApiOperation("增加员工简介")
    public Result addEmployee(@RequestParam(value = "file",required = false) MultipartFile files,EmployeeProfiles e){

        boolean b = employeeProfilesService.saveAll(files,e);
        return Result.success(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMessage(),b);
    }
}





